package com.service.actions;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.HibernateException;

import com.service.hibernate.dao.GenericDAO;
import com.service.hibernate.dao.VehicleDAO;
import com.service.hibernate.pojos.Vehicles;

@SuppressWarnings("serial")
public class VehiclesAction extends GenericAction<Vehicles> {

	Vehicles vehicle = new Vehicles();
	List<Vehicles> vehicles = new ArrayList<Vehicles>();
	GenericDAO<Vehicles> vehicleDAO = new VehicleDAO();

	@Override
	public Vehicles getModel() {
		return vehicle;
	}
	
	@Override
	public String execute() {
		try {
			System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
			System.out.println("In execute...., REG NO : "
					+ vehicle.getVehRegNo() + " TYPE : "
					+ vehicle.getVehType() + " MILEAGE : " + vehicle.getVehMileage()+ " C ID : " + vehicle.getVehCustomerId());
			System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
			vehicleDAO.addData(vehicle);
			return SUCCESS;
		} catch (HibernateException e) {
			System.out.println("----------------------------------------------------------------------------------------------------");
			System.out.println("Error in VehiclesAction - execute Method :");
			e.printStackTrace();
			System.out.println("----------------------------------------------------------------------------------------------------");
			return ERROR;
		}
	}
	
	public String listVehicles(){
		try {
			vehicles=vehicleDAO.getAllData("Vehicles");
			return SUCCESS;
		} catch (HibernateException e) {
			System.out.println("----------------------------------------------------------------------------------------------------");
			System.out.println("Error in VehiclesAction - getVehicles Method :");
			e.printStackTrace();
			System.out.println("----------------------------------------------------------------------------------------------------");
			return ERROR;
		}
	}

	public Vehicles getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicles vehicle) {
		this.vehicle = vehicle;
	}

	public List<Vehicles> getVehicles() {
		return vehicles;
	}

	public void setVehicles(List<Vehicles> vehicles) {
		this.vehicles = vehicles;
	}

	
	
}
